package com.soft.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.soft.entity.Class;
import com.soft.entity.Student;
import com.soft.service.ClassService;

@RestController
@RequestMapping("/class")
public class ClassController {

    @Autowired
    private ClassService classService;

    // 查询所有班级
    @RequestMapping("/queryAll")
    public List<Class> queryAll() {
        return classService.queryAll();
    }
    @RequestMapping("/hello")
    public String hello() {
    	return "nigger！";
    }
    // 插入新班级
    @RequestMapping("/insert")
    public String insert(String name, String num, String departmentId) {
        int res = classService.insert(name, num, departmentId);
        if (res == 1) {
            return name + "添加成功";
        } else {
            return name + "添加失败";
        }
    }

    // 删除班级
    @RequestMapping("/deleteById")
    public String deleteById(String id) {
        int res = classService.deleteById(id);
        if (res == 1) {
            return id + "删除成功";
        } else {
            return id + "删除失败";
        }
    }

    // 根据ID更新num属性
    @RequestMapping("/updateNumById")
    public String updateNumById(String id, String num) {
        int res = classService.updateNumById(id, num);
        if (res > 0) {
            return id + "修改num成功";
        } else {
            return id + "修改num失败";
        }
    }

    // 根据班级名查找该班级所属系所有学生
    @RequestMapping("/getStudentsByClassName")
    public List<Student> getStudentsByClassName(String className) {
        return classService.getStudentsByClassName(className);
    }
}